<%@ page import="edu.polsl.bio.str.common.util.SystemUtils" %>
<%@ page import="edu.polsl.bio.str.node.logic.NodeContext" %>
<%@ page import="edu.polsl.bio.str.node.service.WebControlService" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%

  ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(this.getServletConfig().getServletContext());
  WebControlService controlService = (WebControlService) context.getBean("webControlService");
  NodeContext nodeContext = controlService.getNodeContext();

%>

<html>
<body>
<h2>STR-node INFO</h2>

<table>

  <tbody>
  <tr>
    <td> Is node attached:</td>
    <td><%=nodeContext.isAttached()%>
    </td>
  </tr>
  <tr>
    <td> Node IP:</td>
    <td><%=nodeContext.getNodeIp()%>
    </td>
  </tr>
  <tr>
    <td> Node ID:</td>
    <td><%=nodeContext.getNodeId()%>
    </td>
  </tr>
  <tr>
    <td> Manager IP:</td>
    <td><%=nodeContext.getManagerIp()%>
    </td>
  </tr>
  <tr>
    <td> Number of CPUs:</td>
    <td><%=nodeContext.getNumberOfCpu()%>
    </td>
  </tr>
  <tr>
    <td> Number of active jobs:</td>
    <td><%=nodeContext.getNumberOfActiveJobs()%>
    </td>
  </tr>
  <tr>
    <td> System load:</td>
    <td><%=SystemUtils.getSystemLoad()%>
    </td>
  </tr>

  </tbody>
  <br>

  <table>
    <tbody>
    <tr>
      <form action="rpc/setNodeIp.jsp" method="get">
        <td>Node IP:</td>
        <td><input type="text" name="nodeIp"/></td>
        <td><input type="submit" value="Change node IP"></td>
      </form>
    </tr>
    <tr>
      <form action="rpc/setManagerIp.jsp" method="get">
        <td>Manager IP:</td>
        <td><input type="text" name="managerIp"/></td>
        <td><input type="submit" value="Change manager IP"></td>
      </form>
    </tr>
    <tr>
      <form action="rpc/attach.jsp" method="get">
        <td>Attach to manager:</td>
        <td><input type="text" name="managerIp"/></td>
        <td><input type="submit" value="Attach"></td>
      </form>
    </tr>

    <tr>
      <form action="rpc/detach.jsp" method="get">
        <td>Detach</td>
        <td></td>
        <td><input type="submit" value="Detach"></td>
      </form>
    </tr>
    </tbody>
  </table>

</table>

</body>
</html>
